package com.yanfan.access.service.impl;

import java.util.Arrays;
import java.util.List;
import com.yanfan.common.utils.StringUtils;
import com.yanfan.utils.OauthUtil;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yanfan.access.mapper.NjPersonInfoMapper;
import com.yanfan.access.domain.NjPersonInfo;
import com.yanfan.access.service.INjPersonInfoService;

/**
 * 人员管理Service业务层处理
 *
 * @author genluo
 * @date 2024-11-05
 */
@Service
public class NjPersonInfoServiceImpl extends ServiceImpl<NjPersonInfoMapper, NjPersonInfo> implements INjPersonInfoService {
    @Autowired
    private NjPersonInfoMapper njPersonInfoMapper;


    /**
     * 查询人员管理列表
     *
     * @param njPersonInfo 人员管理
     * @return 人员管理
     */
    @Override
    public List<NjPersonInfo> queryPageList(NjPersonInfo njPersonInfo) {
        LambdaQueryWrapper<NjPersonInfo> lqw = buildQueryWrapper(njPersonInfo);
        List<NjPersonInfo> list = njPersonInfoMapper.selectList(lqw);
        String publicKey = OauthUtil.getPublicKey();
        try {
            String accessToken = OauthUtil.accessToken(publicKey);
            list.stream().forEach(accessRecord->{
                accessRecord.setImageUrl("https://192.168.254.6:443" +
                        "/evo-apigw/evo-oss/" + accessRecord.getImageUrl() + "?token="
                        + accessToken);

            });
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return list;
        //连表查询可用该方法，在此方法SQL语句上进行扩展
        //return njPersonInfoMapper.queryPageList(njPersonInfo);
    }

    /**
    * 分页查询条件
    * @return
    */
    private LambdaQueryWrapper<NjPersonInfo> buildQueryWrapper(NjPersonInfo bo) {
        LambdaQueryWrapper<NjPersonInfo> lqw = Wrappers.lambdaQuery();
        lqw.like(StringUtils.isNotBlank(bo.getName()), NjPersonInfo::getName, bo.getName());
        lqw.eq(bo.getBirthday() != null, NjPersonInfo::getBirthday, bo.getBirthday());
        lqw.like(StringUtils.isNotBlank(bo.getPaperTypeName()), NjPersonInfo::getPaperTypeName, bo.getPaperTypeName());
        lqw.like(StringUtils.isNotBlank(bo.getNationName()), NjPersonInfo::getNationName, bo.getNationName());
        lqw.like(StringUtils.isNotBlank(bo.getDepartmentName()), NjPersonInfo::getDepartmentName, bo.getDepartmentName());
        lqw.eq(bo.getRecordUpdateTime() != null, NjPersonInfo::getRecordUpdateTime, bo.getRecordUpdateTime());
        return lqw;
    }



}
